#include<iostream>
#include<algorithm>
using namespace std;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
struct node
{
	int x;
	int y;
	int z;
}a[N];
int fa[N];
int n, m;
int find(int x)
{
	if (x == fa[x])
	{
		return x;
	}
	else return fa[x] = find(fa[x]);
}
bool cmp(node a,node b)
{
	return a.z < b.z;
}
int kk()
{
	sort(a + 1, a + 1 + m, cmp);

	int ret = 0;
	int cnt = 0;
	for (int i = 1;i <= m;i++)
	{
		int x = a[i].x;
		int y = a[i].y;
		int z = a[i].z;

		int fx = find(x);int fy = find(y);
		if (fx!=fy)
		{
			fa[fx] = fa[fy];//一定是一个节点的父亲与其他节点合并
			ret += z;
			cnt++;
		}
	}
	if (cnt == n - 1) return ret;
	else return INF;
}
int main()
{
	cin >> n >> m;
	for (int i = 1;i <= m;i++)
	{
		cin >> a[i].x >> a[i].y >> a[i].z;
	}
	for (int i = 1;i <= n;i++) fa[i] = i;

	int ret = kk();
	if (ret == INF) cout << "orz" << endl;
	else cout << ret << endl;
	return 0;
}